#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
#include "liso_logging.h"

static FILE *logfile;	/* log file */

void liso_logging_create_log_file(char *fname)
{
	if ((logfile = fopen(fname, "w")) == NULL) {
		fprintf(stderr, "Error creating log file.\n");
		exit(EXIT_FAILURE);
	}
}

void liso_logging_close_log_file()
{
	if (fclose(logfile) != 0) {
		fprintf(stderr, "Error closing log file.\n");
		exit(EXIT_FAILURE);
	}
}

void liso_logging_log(char *name, char *func, char *statement, ...)
{
	va_list ap;
	va_start(ap, statement);

	char timebuf[100];
	time_t rawtime;
	rawtime = time(NULL);
	strftime(timebuf, sizeof(timebuf), "%x %H:%M:%S", localtime(&rawtime));
	fprintf(logfile, "%s:	%s--%s: ", timebuf, name, func);
	vfprintf(logfile, statement, ap);
}
